package com.kt.controller;


import com.kt.model.OverallMetrics;
import com.kt.model.ProductSales;
import com.kt.model.StoreSales;
import com.kt.service.StoreSalesService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.annotation.Resource;
import java.util.List;

@Controller
public class DemoController {
    @Resource
    private StoreSalesService storeSalesService;

    /**
     * 数据大屏首页
     */
    @GetMapping({"/", "/dashboard"})
    public String index(Model model) {
        // 1. 获取门店销售数据（含完成率、同比）
        List<StoreSales> storeSalesList = storeSalesService.getStoreSalesWithMetrics();
        model.addAttribute("storeSales", storeSalesList);

        // 2. 获取销售额前六的门店（用于浮动排名展示）
        List<StoreSales> top6Stores = storeSalesService.getTop6StoresBySales();
        model.addAttribute("top6Stores", top6Stores);

        // 3. 获取产品销售数据
        List<ProductSales> productSalesList = storeSalesService.getProductSalesData();
        model.addAttribute("products", productSalesList);

        // 4. 获取销售额前六的产品（用于表格展示）
        List<ProductSales> top6Products = storeSalesService.getTop6ProductsBySales();
        model.addAttribute("top6Products", top6Products);

        // 5. 获取总体指标（含折扣率、售空率）
        OverallMetrics overallMetrics = storeSalesService.getOverallMetrics();
        model.addAttribute("overallMetrics", overallMetrics);

        return "index";
    }
}

